#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    cin.ignore();
    string num;
    vector<int> nums;
    int t = n;
    while (n--) {
        int val;
        cin >> val;
        nums.push_back(val);
    }
    cin.ignore();
    n = t;
    int idx = 0;
    while (t--) {
        if (t == n) {
            num += to_string(nums[idx++]);
        } else {
            num += " " + to_string(nums[idx++]);
        }
    }

    while (m--) {
        int yy;
        cin >> yy;
        if (yy == 1) {
            string s1, s2;
            cin.ignore();
            getline(cin, s1);
            getline(cin, s2);
            auto pos = num.find(s1);
            if (pos != string::npos) {
                int len = s1.length();
                string s11 = num.substr(0, pos);
                string s22 = num.substr(pos + len);
                num = s11 + s2 + s22;
                nums.clear();
                int v = 0;
                for (int i = 0; i < num.length(); ++i) {
                    if (isdigit(num[i])) {
                        v = v * 10 + (num[i] - '0');
                    }
                    if (!isdigit(num[i]) || i == num.length() - 1) {
                        if (i == num.length() - 1 && isdigit(num[i])) {
                            nums.push_back(v);
                        } else if (i != 0) {
                            nums.push_back(v);
                            v = 0;
                        }
                    }
                }
            }
        } else if (yy == 2) {
            vector<int> newNums;
            for (int j = 0; j < nums.size(); ++j) {
                newNums.push_back(nums[j]);
                if (j < nums.size() - 1 && (nums[j] + nums[j + 1]) % 2 == 0) {
                    newNums.push_back((nums[j] + nums[j + 1]) / 2);
                }
            }
            nums = newNums;
            num.clear();
            for (int i = 0; i < nums.size(); ++i) {
                if (i > 0) {
                    num += " ";
                }
                num += to_string(nums[i]);
            }
        } else if (yy == 3) {
            int l, r;
            cin >> l >> r;
            l--; r--;  // 转换为 0 索引
            for (int i = 0; i < (r - l + 1) / 2; ++i) {
                swap(nums[l + i], nums[r - i]);
            }
            num.clear();
            for (int i = 0; i < nums.size(); ++i) {
                if (i > 0) {
                    num += " ";
                }
                num += to_string(nums[i]);
            }
        }
    }
    cout << num;
    return 0;
}    